import { IUI, IUIContext } from "../../core/common/Common";
import AppConfig from "../../core/config/AppConfig";
import game from "../../core/game";
import { UIBase } from "../../core/gui/UIBase";
import { Logger } from "../../core/log/logger";
import { SoundType } from "../../core/sound/SoundConst";
import SoundHelp from "../../core/sound/SoundHelp";
import Utils from "../../core/utils/Utils";
import EventType from "../../module/common/EventType";
import UI_main_dlg from "../../moduleui/main/UI_main_dlg";

export default class MainDlg extends UIBase<UI_main_dlg> {

    private oldPos: { x: number, y: number } = { x: 0, y: 0 };

    protected createView(): UI_main_dlg {
        return UI_main_dlg.createInstance();
    }



    protected onOpen(data?: any): void {
        let v = this.view;
        v.m_btn.onClick(this, this.close);
        this.on(EventType.GameLoop, this.updateTime);

        v.m_btn1.onClick(this, this.onEffClick);
        // this.view.m_lblTitle.text = "欢迎来到龙之谷";
        this.oldPos = { x: v.m_lblTitle.x, y: v.m_lblTitle.y };

        // Logger.logBusiness(Long.MAX_VALUE, "Log long max value:")
        game.sound.play(Utils.formatString(AppConfig.SOUND_PATH, "bgmusic"), SoundType.Bgm)
    }

    protected onClose(reaskon?: any): void {
        game.sound.stop(SoundType.Bgm);
    }

    private updateTime() {
        // console.log("当前时间：", game.get(TimeManage).second);

    }

    private onEffClick() {
        let skin = "images/boneAnim/zhuque.sk";
        // this.createSk(skin).setXY(300, 500).play(0).play(1).play(2).play(3).play(4).play(5).play(0).dispose();
        game.sound.play(SoundHelp.ButtonBase, SoundType.Button);

        // let tween = new Tween(this.view.m_lblTitle, true);
        // tween.to({ x: this.oldPos.x + Utils.randomInt(-300, 300), y: this.oldPos.y + Utils.randomInt(-300, 300) }, 300)
        //     .easing(Easing.Back.In)
        //     .start(Laya.timer.currTimer);
    }
}